"""Definition of the navlink content type
"""

from zope.interface import implements

from Products.Archetypes import atapi
from Products.ATContentTypes.content import base
from Products.ATContentTypes.content import schemata

#from Products.ATContentTypes.content.image import ATImage,ATImageSchema
from Products.ATContentTypes.content.newsitem import ATNewsItem,ATNewsItemSchema
#from Products.ATContentTypes.lib.imagetransform import ATCTImageTransform
#from Products.validation import V_REQUIRED

# -*- Message Factory Imported Here -*-
from my315ok.xtinfocontent import xtinfocontentMessageFactory as _

from my315ok.xtinfocontent.interfaces import Inavlink
from my315ok.xtinfocontent.config import PROJECTNAME


navlinkSchema = ATNewsItemSchema.copy() + atapi.Schema((

    # -*- Your Archetypes field definitions here ... -*-    
    atapi.StringField(
        'link',
        storage=atapi.AnnotationStorage(),       
       
        widget=atapi.StringWidget(
            label=_(u"link url"),
            description=_(u""),
        ),
        required=True,
        validators=('isURL'),
    ),


    atapi.ImageField(
        'iconimage',
#         primary=True,
         
        storage=atapi.AnnotationStorage(),
      
        widget=atapi.ImageWidget(
            label=_(u"link icon"),
            description=_(u""),
        ),
        validators=('isNonEmptyFile'),
    ),

   atapi.StringField(
        'ltag',
        storage=atapi.AnnotationStorage(),
        vocabulary_factory=u"my315ok.xtinfocontent.navtag",
        enforceVocabulary=True,
        widget=atapi.SelectionWidget(
            label=_(u"link tag"),
            description=_(u""),
        ),
        required=True,
    ),
    atapi.StringField(
        'tag',
        storage=atapi.AnnotationStorage(),
        vocabulary_factory=u"my315ok.xtinfocontent.navtag",
#        enforceVocabulary=True,
        widget=atapi.SelectionWidget(
            label=_(u"link tag"),
            description=_(u""),
            
        ),
    ),


))

# Set storage on fields copied from ATContentTypeSchema, making sure
# they work well with the python bridge properties.

navlinkSchema['title'].storage = atapi.AnnotationStorage()
navlinkSchema['description'].storage = atapi.AnnotationStorage()
navlinkSchema['title'].widget.label = _(u"link title")
navlinkSchema['title'].widget.description = _(u"")
navlinkSchema['tag'].widget.visible = 0
navlinkSchema['iconimage'].widget.visible = 0
navlinkSchema['text'].widget.visible = 0
navlinkSchema['imageCaption'].widget.visible = 0

#navlinkSchema['image'].required = False
#navlinkSchema['image'].pramary = False
#navlinkSchema['image'].validators = ()

schemata.finalizeATCTSchema(navlinkSchema, moveDiscussion=False)


class navlink(ATNewsItem):
    """a navigation link"""
    implements(Inavlink)

    meta_type = "navlink"
    schema = navlinkSchema
    _at_rename_after_creation = True

    title = atapi.ATFieldProperty('title')
    description = atapi.ATFieldProperty('description')

    # -*- Your ATSchema to Python Property Bridges Here ... -*-
    ltag = atapi.ATFieldProperty('ltag')

    
    link = atapi.ATFieldProperty('link')

    iconimage = atapi.ATFieldProperty('iconimage')

    tag = atapi.ATFieldProperty('tag')


atapi.registerType(navlink, PROJECTNAME)
